package by.koleda.photoupdater.helpers;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

public class ListJsonObjectTask extends CommonAsyncTask<List<JSONObject>> {

	public ListJsonObjectTask(ParamCallback<List<JSONObject>> paramCallback) {
		super(paramCallback);
	}

	@Override
	public List<JSONObject> convert(String source) throws Exception {
		if (source == null || source.length() == 0) {
			return null;
		}
		JSONArray array = new JSONArray(source);
		if (array.length() == 0) {
			return null;
		}
		List<JSONObject> list = new ArrayList<JSONObject>();
		for (int i = 0; i < array.length(); i++) {
			list.add(array.getJSONObject(i));
		}
		return list;
	}

}
